<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>博客修改</title>
    <meta name="referrer" content="no-referrer"/>
    <link th:href="@{/css/bootstrap-3.3.7-dist/css/bootstrap.css}" rel="stylesheet">
    <link th:href="@{/css/bootstrap-3.3.7-dist/css/bootstrap-theme.css}" rel="stylesheet">
    <link th:href="@{/css/blog.css}" rel="stylesheet">
    <link th:href="@{/css/adminblog.css}" rel="stylesheet">
    <link th:href="@{/lib/editormd/css/editormd.min.css}" rel="stylesheet">
<!--    <link th:href="@{/lib/bootstrap-select/bootstrap-select.min.css}" rel="stylesheet">-->
    <script type="text/javascript" th:src="@{/js/jquery-3.0.0.js}"></script>
    <script type="text/javascript" th:src="@{/js/jquery-3.0.0.min.js}"></script>
    <script type="text/javascript" th:src="@{/css/bootstrap-3.3.7-dist/js/bootstrap.js}"></script>
    <script type="text/javascript" th:src="@{/css/bootstrap-3.3.7-dist/js/bootstrap.min.js}"></script>
<!--    <script type="text/javascript" th:src="@{/css/bootstrap-3.3.7-dist/js/npm.js}"></script>-->
    <script type="text/javascript" th:src="@{/lib/editormd/editormd.min.js}"></script>
<!--    <script type="text/javascript" th:src="@{/lib/bootstrap-select/bootstrap-select.min.js}"></script>-->
<!--    <script type="text/javascript" th:src="@{/lib/bootstrap-select/defaults-zh_CN.min.js}"></script>-->

</head>
<body style="background-color: #F2F2F2">
<div th:replace="admin/adminblog::adminheader"></div>
<div>
    <div class="container">
        <form id="blog-form" th:object="${blog}" action="#" th:action="@{/admin/blogsave}" method="post">
            <input type="hidden" name="id" th:value="*{id}">
            <input type="hidden" name="published">
            <div class="row">
                <div class="col-xs-3">
                    <div class="form-group">
                        <select class="form-control" name="flag" th:value="*{flag}">
                            <option th:value="*{flag}" th:text="*{flag}"></option>
                            <option value="原创">原创</option>
                            <option value="转载">转载</option>
                            <option value="翻译">翻译</option>
                        </select>
                    </div>
                </div>
                <div class="col-xs-9">
                    <input type="text" class="form-control" name="title" id="title" placeholder="标题" th:value="*{title}">
                </div>
            </div>
            <div class="form-group">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea class="form-control" rows="8" placeholder="博客内容" name="content" id="content" th:text="*{content}"></textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="row">
                    <div class="col-xs-6">
                        <div class="form-group form-group-sm">
                            <label class="col-sm-2 control-label" style="font-size: 20px;" for="typeId">分类</label>
                            <div class="col-sm-10">
                                <select class="form-control" id="typeId" name="type.id" >
                                    <option th:value="*{type.id}" th:text="*{type.name}"></option>
                                    <option th:each="type : ${types}" th:value="${type.id}" th:text="${type.name}"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="col-xs-6">
                        <div class="form-group form-group-sm">
                            <label class="col-sm-2 control-label" style="font-size: 20px;" for="tagIds">标签</label>
                            <div class="col-sm-10">
                                <select class="form-control" name="tag" id="tagIds">
                                    <option th:value="*{tag.id}" th:text="*{tag.name}"></option>
                                    <option th:each="tag : ${tags}" th:value="${tag.id}" th:text="${tag.name}"></option>
                                </select>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label class="checkbox-inline">
                    <input type="checkbox" id="recommend" name="recommend" th:checked="*{recommend}"> 推荐
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="shareStatement" name="shareStatement" th:checked="*{shareStatement}"> 转载声明
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="appreciation" name="appreciation" th:checked="*{shareStatement}"> 赞赏
                </label>
                <label class="checkbox-inline">
                    <input type="checkbox" id="commentabled" name="commentabled" th:checked="*{shareStatement}"> 评论
                </label>
            </div>
            <div class="form-group">
                <div class="row">
                    <label class="col-sm-1 control-label" style="font-size: 20px;text-align: center" for="firstPicture">首图</label>
                    <div class="col-sm-11">
                        <input type="text" class="form-control" id="firstPicture" aria-describedby="basic-addon3" name="firstPicture" th:value="*{firstPicture}" placeholder="首图引用地址">
                    </div>
                </div>
            </div>
            <div class="form-group">
                <textarea class="form-control" rows="5" id="description" name="description" th:text="*{description}" placeholder="博客描述..." maxlength="200"></textarea>
            </div>
            <div class="form-group">
                <div style="float: right">
                    <button type="button" class="btn btn-default" onclick="window.history.go(-1)">返回</button>
                    <button type="button" id="save-btn" class="btn btn-success">保存</button>
                    <button type="button" id="publish-btn" class="btn btn-primary">发布</button>
                </div>
            </div>
        </form>
    </div>
</div><br>
<div th:replace="admin/adminblog::adminfooter"></div>

<script type="text/javascript">
    $('.dropdown-toggle').dropdown()
    //初始化Markdown编译器
    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
            path    : "/lib/editormd/lib/"
        });

    });



    $("#save-btn").click(function () {
        $("[name='published']").val(false);
        $("#blog-form").submit();
    })

    $("#publish-btn").click(function () {
        $("[name='published']").val(true);
        $("#blog-form").submit();
    })

    var $title = $("#title")
    var $content= $("#content")
    var $typeId = $("#typeId")
    var $firstPicture = $("#firstPicture")
    var $description = $("#description")
    $(document).ready(function () {
        $("#form").submit(function () {
            if (title() && content() && typeId() && firstPicture() && description()){
                return true
            }else {
                return false
            }
        })
    })

    function title() {
        if ($title.val() == ""){
            window.alert("标题不能为空")
            return false
        }
        return true
    }
    function content() {
        if ($content.val() == ""){
            window.alert("内容不能为空")
            return false
        }
        return true
    }
    function typeId() {
        if ($typeId.val() == ""){
            window.alert("分类不能为空")
            return false
        }
        return true
    }
    function firstPicture() {
        if ($firstPicture.val() == ""){
            window.alert("首图不能为空")
            return false
        }
        return true
    }
    function description() {
        if ($description.val() == ""){
            window.alert("博客描述不能为空")
            return false
        }
        return true
    }

</script>

<script type="text/javascript">
    $("#newBlog-container").load(/*[[@{/footer/newBlog}]]*/"/footer/newBlog")
</script>
</body>
</html>